package ee.pri.pink.kallur.gl.objects;

import java.util.LinkedList;
import java.util.List;

import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLU;

public class GLWorld implements GLObject {
	
	private List<GLObjectInstance> objects;
	
	public GLWorld() {
		objects = new LinkedList<GLObjectInstance>();
	}

	@Override
	public void render(GL10 gl) {
		
//		gl.glRotatef(1.0f, 0.0f, 0.0f, 1.0f);
		
		gl.glPushMatrix();
		
		GLU.gluLookAt(gl, 13.5f, 2.5f, -20.0f, 13.5f, 0.0f, 2.5f, 0.0f, 1.0f, 0.0f);
		
//		gl.glTranslatef(0, 0, 10.0f);
		
		for (GLObjectInstance obj : objects) {
			gl.glPushMatrix();
			// transform
			
			gl.glTranslatef(obj.x, obj.y, obj.z);
			
			obj.model.render(gl);
			
			// untransform
			gl.glPopMatrix();
		}
		
		gl.glPopMatrix();
	}
	
	public GLObjectInstance addObject(GLObject object, float x, float y, float z) {
		GLObjectInstance inst = new GLObjectInstance(object, x, y, z);
		objects.add(inst);
		return inst;
	}
}
